package com.framework.service.yhbservice.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.YHBDao.user.YhbUserTerminalRelationDao;
import com.framework.service.yhbservice.YhbUserTerminalRelationService;
import com.framework.yhbEntity.user.YhbCusTer;
import com.framework.yhbEntity.user.YhbUser;
import com.framework.yhbEntity.user.YhbUserTerminalRelation;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author wq
 */
@Transactional(rollbackFor = Exception.class)
@Service("yhbUserTerminalRelationService")
public class YhbUserTerminalRelationServiceImpl extends ServiceImpl<YhbUserTerminalRelationDao,YhbUserTerminalRelation>
                                                    implements YhbUserTerminalRelationService {


    @Override
    public YhbUserTerminalRelation queryRelationBySn(String sn) {
        YhbUserTerminalRelation r=new YhbUserTerminalRelation();
        r.setSn(sn);
        r.setIsDel(0);
        return baseMapper.selectOne(r);
    }

    @Override
    public void addRelation(YhbCusTer yct, YhbUser user) {
        YhbUserTerminalRelation r=new YhbUserTerminalRelation();
        r.setIsUse(1);
        r.setSn(yct.getSn());
        r.setUserId(user.getUserId());
        r.setCreateDate(new Date());
        baseMapper.insert(r);
    }

    @Override
    public void deleteTerminal(YhbUserTerminalRelation r) {
        baseMapper.deleteTerminal(r);
    }

    @Override
    public void updateRelation(YhbUserTerminalRelation relation) {
        baseMapper.updateRelation(relation);
    }

    @Override
    public Integer querySnOwnerNum(String userId) {
        return baseMapper.querySnOwnerNum(userId);
    }

    @Override
    public List<Long> querySnOwnerList(String userId) {
        return baseMapper.querySnOwnerList(userId);
    }

    @Override
    public void activSn(String sn) {
        baseMapper.setActivitySn(sn);
    }
}
